﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using PGI.EN.OpcSistxTipoUsuario;

namespace PGI.AD.OpcSistxTipoUsuario
{
    public class OpcSistxTipoUsuarioAd
    {
        public static int OpcSistxTipoUsuario_CambiarEstadoNoHabilitado(OpcSistxTipoUsuarioEn os_tuEn)
        {
            SqlCommand command = null;
            SqlConnection connection = null;
            SqlDataReader reader = null;

            string sql = "MntOpcSistxTipoUsuarioUEstado";

            try
            {
                connection = DataBaseFactory.SqlOpenDatabase("PGI");
                command = new SqlCommand(sql, connection);

                command.CommandType = CommandType.StoredProcedure;

                command.Parameters.AddWithValue("@OpcSistemaID", os_tuEn.OpcSistemaID);
                command.Parameters.AddWithValue("@TipoUsuarioID", os_tuEn.TipoUsuarioID);
                command.Parameters.AddWithValue("@Estado", os_tuEn.Estado);
                
                command.Parameters.Add("@Resultado", SqlDbType.Int).Direction = ParameterDirection.Output;


                command.ExecuteNonQuery();

                int resultado = Convert.ToInt32(command.Parameters["@Resultado"].Value);

                return resultado;
            }

            catch (SqlException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            finally
            {
                if (reader != null)
                    reader.Close();
                DataBaseFactory.SqlCloseDatabase("PGI");
            }
        }
        public static int OpcSistxTipoUsuario_InsertarOpcion(OpcSistxTipoUsuarioEn os_tuEn)
        {
            SqlCommand command = null;
            SqlConnection connection = null;
            SqlDataReader reader = null;

            string sql = "MntOpcSistxTipoUsuarioIOpcion";

            try
            {
                connection = DataBaseFactory.SqlOpenDatabase("PGI");
                command = new SqlCommand(sql, connection);

                command.CommandType = CommandType.StoredProcedure;

                command.Parameters.AddWithValue("@OpcSistemaID", os_tuEn.OpcSistemaID);
                command.Parameters.AddWithValue("@TipoUsuarioID", os_tuEn.TipoUsuarioID);

                command.Parameters.Add("@Resultado", SqlDbType.Int).Direction = ParameterDirection.Output;


                command.ExecuteNonQuery();

                int resultado = Convert.ToInt32(command.Parameters["@Resultado"].Value);

                return resultado;
            }

            catch (SqlException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            finally
            {
                if (reader != null)
                    reader.Close();
                DataBaseFactory.SqlCloseDatabase("PGI");
            }
        }
    }
}
